package mall.mybatis.util;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;



public class SessionUtil {
	private SqlSessionFactory factory;
	private static SessionUtil instance = null;
	
	private SessionUtil(){
		String resource = "mybatis_config.xml";
		InputStream is = SessionUtil.class.getClassLoader().getResourceAsStream(resource);
		factory = new SqlSessionFactoryBuilder().build(is);
	}
	
	public static SessionUtil getInstance() {
		if (instance == null) {
			instance = new SessionUtil();
		}
		return instance;
	}
	
	public SqlSession openSession() {
		return this.factory.openSession();
	}
	
	
	
}
